Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CA-407106: fix various XHA warnings from the Clang static analyzer #22

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

edwintorok
Copy link
Contributor

No description provided.

@freddy77
Copy link
Collaborator

A description would be nice

@freddy77
Copy link
Collaborator

Can you clean the binary files?

@edwintorok
Copy link
Contributor Author

Can you clean the binary files?

Thanks for spotting that, looks like gitignore isn't set correctly, I'll fix that.

`sm_fence` didn't declare what arguments it takes, but this is
deprecated.

```
../include/sm.h:368:1: warning: a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C23, conflicting with a subsequent definition [-Wdeprecated-non-prototype]
sm.c:530:1: note: conflicting prototype is here
```

Signed-off-by: Edwin Török <[email protected]>
Nested functions are a GCC-only extension and are not supported by clang
and clangd at all.

Signed-off-by: Edwin Török <[email protected]>
These are either set again later to another value, or never read.

Signed-off-by: Edwin Török <[email protected]>
The code always gets 10 return addresses, however we can't know for sure that we actually have 10 addresses on the stack.
We might try to read beyond the stack and crash.

The compiler warns about this:
```
log.c:452:9: warning: calling ‘__builtin_frame_address’ with a nonzero argument is unsafe [-Wframe-address]
  452 |     if (__builtin_frame_address(x) == 0)                \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
log.c:471:5: note: in expansion of macro ‘FILL_RETURN_ADDRESS’
```

Instead use a GNU libc specific function: backtrace and backtrace_symbols to get a stacktrace safely.
This is a short live program and would close it on exit anyway,
but we don't want to ignore this kind of error in the rest of the program.

Signed-off-by: Edwin Török <[email protected]>
If a timeout is reached, then the loop is never entered, and 'index' is uninitialized.
All the logging calls would use an uninitialized value, and later `my_sfdomain` would also be uninitialized
and various decisions would be taken based on its state.

Ensure that these variables are initialized at least once in the loop by moving the timeout condition.

It is very unlikely that this'd actually happen, but without this change the static analyzer
wouldn't be able to spot other bugs that'd leave these values uninitialized.

Signed-off-by: Edwin Török <[email protected]>
Comment on lines +8 to +9
compile_commands.json
.cache/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid adding specific tool settings.

@edwintorok edwintorok force-pushed the private/edvint/warnings branch from 8c4fc0b to c8347fc Compare February 24, 2025 15:17
Use `sigaction` and `sigprocmask` instead.
There is also `signal`, but the manpage says to not use it.
Indeed `sigaction` has more reliable semantics by default in POSIX (e.g. it blocks the signal while you are handling it,
so you don't reenter it while it is executing).

Unfortunately the new functions are more verbose, so introduce a loop for setting up the signal handlers.

Signed-off-by: Edwin Török <[email protected]>
Also disable warnings we can't/don't want to fix now:
* clang-diagnostic-reserved-macro-identifier
 The bug is in Xen, it mandates using `__XEN_TOOLS__` in `sysctl.h`


Signed-off-by: Edwin Török <[email protected]>
@edwintorok edwintorok force-pushed the private/edvint/warnings branch from c8347fc to d7919a1 Compare February 24, 2025 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants